<?php

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	  /**
     * [商城首页]
     * @return [array] [description]
     * @author Weiliqiang <[<email address>]>
     */
    public function index()
    {

        // 查询大轮播图数据
        $slide_image = D('slider')->field('save_path,save_name,title')->where('status=1')->select();

        foreach($slide_image as $k=>$v){
          $slide_image[$k]['image_path'] = ltrim($v['save_path'],'.').$v['save_name'];
        }

        // 查询热销商品前十的数据
        $hot_goods = D('goods')
                        ->alias('a')
                        ->join("north_image b ON a.goods_id=b.goods_id")
                        ->join("north_attr c ON a.goods_id=c.goods_id")
                        ->order("c.sale desc")
                        ->group("a.goods_id")
                        ->limit(10)
                        ->field("a.goods_id,a.name goods_name,a.price,b.path,b.name image_name,c.sale")
                        ->select();

        foreach($hot_goods as &$v){
            $v['image_path'] = "Uploads".ltrim($v['path'],'.').$v['image_name'];
        }

        $this->assign('list',$slide_image);
        $this->assign('hot_goods',$hot_goods);
        
        $this->display();
    }

}